package com.example.ws.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mybatis config
 * @MapperScan()指定Mybatis的Mapper接口包所在位置
 */
@Configuration
@MapperScan("com.example.ws.mapper")
public class MybatisConfig {
    /**
     * 分页插件（无它，分页不支持）
     */
    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor(){
        //  PaginationInnerInterceptor是Mybatis-puls框架中的一个类，用于处理分页请求
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        //设置最大单页限制数量，默认500条，-1不受限
        paginationInnerInterceptor.setMaxLimit(500L);

        return paginationInnerInterceptor;
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
